﻿using Microsoft.Extensions.DependencyInjection;
using System;
using Xc.DataAccess.Protocoals.WaterMeters.Services;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ApplicationExtension
    {
        /// <summary>
        /// 添加表具套接字服务端
        /// 注入服务有：
        /// <list type="number">
        ///     <item>业务处理服务 <see cref="IMeterHandleService"/></item>
        ///     <item>业务管理服务 <see cref="IWaterMeterSocketService"/></item>
        /// </list>
        /// </summary>
        /// <param name="serviceDescriptors"></param>
        /// <returns></returns>
        public static IServiceCollection AddWaterMeterSocketServer(this IServiceCollection serviceDescriptors)
        {
            serviceDescriptors.AddSingleton<IMeterHandleService, MeterHandleService>();
            serviceDescriptors.AddSingleton<IWaterMeterSocketService, WaterMeterSocketService>();
            return serviceDescriptors;
        }
        public static IServiceCollection AddWaterMeterSocketServer<THandleService>(this IServiceCollection serviceDescriptors) where THandleService: MeterHandleService
        {
            serviceDescriptors.AddSingleton<IMeterHandleService, THandleService>();
            serviceDescriptors.AddSingleton<IWaterMeterSocketService, WaterMeterSocketService>();
            return serviceDescriptors;
        }
        /// <summary>
        /// 获取水表套接字服务
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static IWaterMeterSocketService GetWaterMeterSocketService(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetService<IWaterMeterSocketService>();
        }
        /// <summary>
        /// 获取在线设备操作服务
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public static IMeterHandleService GetMeterHandleService(this IServiceProvider serviceProvider)
        {
            return serviceProvider.GetService<IMeterHandleService>();
        }
    }
}
